// 商品列表接口
import http from '../service/http';

// 获取商品列表
export const goodList = (current) =>{
    return http({
        url: '/goods/list',
        method: 'get',
        params: {
            pagesize: 10,
            current
        }
    })
}
// 搜索商品
export const searchItem = (search,current) =>{
    return http({
        url: '/goods/list',
        method: 'get',
        params: {
            pagesize: 10,
            search,
            current
        }
    })
}

// 获取商品详情信息
export const goodItem = (id) =>{
    return http({
        url: '/goods/item',
        method: 'get',
        params: {
            id
        }
    })
}

// 获取分类列表
export const kindList = () =>{
    return http({
        url: '/goods/category',
        method: 'get'
    })
}
// 按照商品分类获取商品列表
export const categoryItem = (category,current) =>{
    return http({
        url: '/goods/list',
        method: 'get',
        params: {
            pagesize: 10,
            category,
            current
        }
    })
}
// 热销商品
export const getHot = (current) =>{
    return http({
        url: '/goods/list',
        method: 'get',
        params: {
            pagesize: 10,
            filter: 'hot',
            current
        }
    })
}
// 打折商品
export const getSale = (current) =>{
    return http({
        url: '/goods/list',
        method: 'get',
        params: {
            pagesize: 10,
            filter: 'sale',
            current
        }
    })
}
// 价格升序
export const priceUp = (current) =>{
    return http({
        url: '/goods/list',
        method: 'get',
        params: {
            pagesize: 10,
            sortType: 'price',
            sortMethod: 'ASC',
            current
        }
    })
}
// 价格降序
export const priceDown = (current) =>{
    return http({
        url: '/goods/list',
        method: 'get',
        params: {
            pagesize: 10,
            sortType: 'price',
            sortMethod: 'DESC',
            current
        }
    })
}

// 加入推荐
// 须登录后才可使用
export const addItem = (id,goodsId) =>{
    return http({
        url: '/cart/add',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            authorization: sessionStorage.getItem('token'),
          },
        data: {
            id,
            goodsId
        }
    })
}
